package grape.composite.rest.appbanner.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.composite.service.appbanner.query.AppBannerListQuery;
import grape.composite.rest.appbanner.form.AppBannerCreateForm;
import grape.composite.rest.appbanner.form.AppBannerUpdateForm;
import grape.composite.rest.appbanner.mapper.AppBannerWebMapper;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;

import grape.composite.rest.appbanner.form.AppBannerListPageForm;
import grape.composite.rest.appbanner.vo.AppBannerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.composite.service.appbanner.po.AppBanner;
import grape.composite.service.appbanner.api.IAppBannerService;

/**
 * <p>
 * app横幅表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-03-10
 */
@RestController
@RequestMapping("/composite/appbanner")
@Api(tags = "app横幅相关接口")
public class AppBannerController extends BaseController<AppBannerVo, AppBanner> {

    @Autowired
    private AppBannerWebMapper currentWebMapper;
    @Autowired
    private IAppBannerService currentService;



     @ApiOperation("添加app横幅")
     @PreAuthorize("hasAuthority('appbanner:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public AppBannerVo create(@RequestBody @Valid AppBannerCreateForm cf) {
         AppBanner po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询app横幅")
     @PreAuthorize("hasAuthority('appbanner:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public AppBannerVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除app横幅")
     @PreAuthorize("hasAuthority('appbanner:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新app横幅")
     @PreAuthorize("hasAuthority('appbanner:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public AppBannerVo update(@PathVariable String id,@RequestBody @Valid AppBannerUpdateForm uf) {
         AppBanner po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询app横幅")
    @PreAuthorize("hasAuthority('appbanner:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<AppBannerVo> listPage(AppBannerListPageForm listPageForm) {
         AppBanner po = currentWebMapper.formToPo(listPageForm);
        AppBannerListQuery appBannerListQuery = new AppBannerListQuery();
        appBannerListQuery.setPoQuery(po);
        return super.listPage(appBannerListQuery,listPageForm);
     }

}
